%%%-------------------------------------------------------------------
%%% @author kk
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%% 计算数字列表或元组索引N到M的和
%%% @end
%%% Created : 18. 7月 2024 19:54
%%%-------------------------------------------------------------------
-module(d3).
-author("kk").

%% API
-export([start/0, getIndexSum/3]).

start() ->
  List = [11, 2, 3, 4, 100],
  Sum = getIndexSum(List, 1, 3), % 6
  io:fwrite("~w", [Sum]).

getIndexSum([], Start, End) -> [0, Start, End];
getIndexSum(X, Start, End) when Start =< End -> getIndexSum(X, Start, End, 1, 0).
getIndexSum([H | T], Start, End, Index, Count) ->
  if
    Start =< Index, Index =< End -> Sum = Count + H, io:format("Times: ~w ~w~n", [Sum, Index]), getIndexSum(T, Start, End, Index + 1, Sum);
    true -> Count
  end.

